package com.yonyou.crm.bpub.topbar.service;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.crm.base.brand.entity.BrandVO;
import com.yonyou.crm.base.brand.service.BrandsBizServiceImpl;
import com.yonyou.crm.bpub.topbar.entity.*;
import com.yonyou.crm.common.search.entity.AppSearchPlanEnum;
import com.yonyou.crm.common.sort.entity.AppSortPlanEnum;

@Service
public class ProductTopbar extends BaseTopbar {

	@Autowired
	BrandsBizServiceImpl branchBizService;
	
	@Override
	public PlanVO getPresetOptions(){
		PlanVO presetOption = new PlanVO();
		presetOption.setTitle("预置选择");
		
		List<DataItemVO> data = new ArrayList<>();
		DataItemVO item;
		
		item = new DataItemVO(String.valueOf(AppSearchPlanEnum.ALL.getValue()), AppSearchPlanEnum.ALL.getName());
		data.add(item);
		
		item = new DataItemVO(String.valueOf(AppSearchPlanEnum.FOLLOW.getValue()), AppSearchPlanEnum.FOLLOW.getName());
		data.add(item);
		
		presetOption.setData(data);
		return presetOption;
	};
	
	@Override
	public String getSearchPlaceholder(){
		String searchText = "搜索产品名称、编码、助记码";
		return searchText;
	}
	
	@Override
	public PlanVO getSortData(){
		PlanVO sortData = new PlanVO();
		sortData.setTitle("排序");
		
		List<DataItemVO> data = new ArrayList<>();
		DataItemVO item;
		
		item = new DataItemVO(String.valueOf(AppSortPlanEnum.CODE.getValue()), AppSortPlanEnum.CODE.getName());
		data.add(item);
		
		item = new DataItemVO(String.valueOf(AppSortPlanEnum.MODIFYTIME.getValue()), AppSortPlanEnum.MODIFYTIME.getName());
		data.add(item);

		sortData.setData(data);
		return sortData;
	};
	
	@Override
	public List<SelectDataVO> getSelectData(){
		List<SelectDataVO> selectData = new ArrayList<SelectDataVO>();
		
		SelectDataVO select;
		List<DataItemVO> data;
		DataItemVO item;
		
		select = new SelectDataVO();
		select.setKey("prdtypeId");
		select.setType("class");
		select.setTitle("分类");
		select.setReferto("producttype");
		selectData.add(select);
		
		select = new SelectDataVO();
		select.setKey("attrGroupId");
		select.setType("refer");
		select.setTitle("属性组");
		select.setReferto("attrgroup");
		selectData.add(select);
		
		select = new SelectDataVO();
		select.setKey("brandIds");
		select.setType("multiple");
		select.setTitle("品牌");
		data = new ArrayList<>();
		Map<String, Object> paraMap = new HashMap<>();
		List<BrandVO> brandList = branchBizService.getRefList(paraMap);
		if ((brandList != null) && (brandList.size() > 0)) {
			for(int i = 0; i < brandList.size(); i++) {
				BrandVO brand = brandList.get(i);
				item = new DataItemVO(String.valueOf(brand.getId()), brand.getName());
				data.add(item);
			}
		}
		select.setData(data);
		selectData.add(select);
		
		select = new SelectDataVO();
		select.setKey("enableState");
		select.setType("radio");
		select.setTitle("启用状态");
		data = new ArrayList<>();
		item = new DataItemVO("3", "全部");
		data.add(item);
		item = new DataItemVO("1", "已启用");
		data.add(item);
		item = new DataItemVO("2", "已停用");
		data.add(item);
		select.setData(data);
		selectData.add(select);
		
		return selectData;
	}

}
